Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: notifications - user storage controller #23353

Merged

Conversation

Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Mar 6, 2024

Description

Followup PR on this: #23286
Allows developers to store synced and protected user information where only the user/client can read, write, and access.

This enables Profile Syncing and Notifications.

Open in GitHub Codespaces

Related issues

Fixes: N/A

Manual testing steps

N/A, this controller is unconnected. It will be connected with other controllers in followup PRs.

Screenshots/Recordings

N/A

Before

N/A

After

N/A

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

this allows developers to store synced and secure data that only clients can access

this relies on the authentication controller
Copy link
Contributor

github-actions bot commented Mar 6, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

app/scripts/controllers/user-storage/services.test.ts Dismissed Show dismissed Hide dismissed
app/scripts/controllers/user-storage/services.test.ts Dismissed Show dismissed Hide dismissed
… NOTIFY-415-user-storage-user-storage-controller
@Prithpal-Sooriya Prithpal-Sooriya added the team-notifications Notifications team label Mar 6, 2024
… NOTIFY-415-user-storage-user-storage-controller
other policies we can change, but the build-system policy is specifically for circleCI
… NOTIFY-415-user-storage-user-storage-controller
@Prithpal-Sooriya
Copy link
Contributor Author

Fixing breaking builds & CI. Will mark ready for review one done

@Prithpal-Sooriya Prithpal-Sooriya marked this pull request as ready for review March 12, 2024 12:26
@Prithpal-Sooriya Prithpal-Sooriya requested review from a team as code owners March 12, 2024 12:26
@Prithpal-Sooriya Prithpal-Sooriya changed the title feat: add user storage controller feat: notifications - user storage controller Mar 12, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [2d3aec5]
Page Load Metrics (1546 ± 300 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint742381364019
domContentLoaded97927189
load6121251546626300
domInteractive97927189
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 33.26 KiB (0.89%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

… NOTIFY-415-user-storage-user-storage-controller
this can be used for the notifications controller for trigger creation
Copy link

codecov bot commented Mar 18, 2024

Codecov Report

Attention: Patch coverage is 26.43678% with 128 lines in your changes are missing coverage. Please review.

Project coverage is 67.42%. Comparing base (f0494a1) to head (509bfd4).
Report is 1 commits behind head on develop.

Files Patch % Lines
...ontrollers/user-storage/user-storage-controller.ts 23.94% 54 Missing ⚠️
app/scripts/controllers/user-storage/encryption.ts 22.64% 41 Missing ⚠️
app/scripts/controllers/user-storage/services.ts 22.58% 24 Missing ⚠️
app/scripts/controllers/user-storage/schema.ts 33.33% 6 Missing ⚠️
...ollers/authentication/authentication-controller.ts 75.00% 2 Missing ⚠️
app/scripts/metamask-controller.js 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23353      +/-   ##
===========================================
- Coverage    67.58%   67.42%   -0.15%     
===========================================
  Files         1247     1251       +4     
  Lines        48934    49105     +171     
  Branches     12774    12790      +16     
===========================================
+ Hits         33069    33109      +40     
- Misses       15865    15996     +131     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@metamaskbot
Copy link
Collaborator

Builds ready [85ebd42]
Page Load Metrics (1218 ± 551 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint742181203818
domContentLoaded106325136
load60267912181148551
domInteractive106325136
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 33.29 KiB (0.92%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@@ -0,0 +1,117 @@
import sjcl from 'sjcl';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need a wider discussion on this.

Context

All MetaMask Clients (mobile, extension, portfolio) that want to use UserStorage must all use the same encryption/decryption mechanism.

Any data you store must be encrypted, and any data you retrieve must be decrypted.

This is what was approved on Portfolio - basic symmetric encryption using the storage key as the password.

Discussion

Can we also use this for extension? What are the risks? If there are other encryption mechanisms that we need, we will need it to be compatible for all metamask clients and also need to port Portfolio to use the same encryption mechanism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the storage key a symmetric key?

Also, we should rather use a KDF instead of a PBKDF if we are already working with cryptographic material.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep the storage key is symmetric. And yep flexible to change to KDF.
TBH if there is a need to change to asymmetric encryption/decryption I think we can - I'll note this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a usecase for assymetric cryptography here. Care to elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - I don't see a need for asymmetric encryption - was open to it if it is recommended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks all! Closing this discussion.

As discussed we have a Threat Modelling Document here
Also tickets here

… NOTIFY-415-user-storage-user-storage-controller
we needed a way of disabling/enabling user storage/profile syncing
* @returns the storage key
*/
async #createStorageKey(): Promise<string> {
const id = await this.#auth.getSessionIdentifier();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the key used for encryption needs the session idenitfier. How is the session identifier deterministically generated across different installs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call out!

The session identifier here comes from our auth server. Under the hood this will be the "Auth V2 Profile Id", where we can sync multiple "logins" with the same profile.

View Doc

@Prithpal-Sooriya
Copy link
Contributor Author

Blocking this PR until the Security Threat Model Discussions have been concluded.

… NOTIFY-415-user-storage-user-storage-controller
Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once the security questions are resolved and my latest comment is resolved, I think I am good with this PR

* actions.
*/
#registerMessageHandlers(): void {
this.messagingSystem.registerActionHandler(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know we registered these handlers for the messaging system. Makes sense!

@@ -152,6 +190,10 @@ export default class AuthenticationController extends BaseController<
return profile;
}

public isSignedIn(): boolean {
return this.state.isSignedIn;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev Note - this is so state can be exposed through the messaging system. If we need to expose more state for other controllers we can widen this (or create new methods)

@metamaskbot
Copy link
Collaborator

Builds ready [9e7ace6]
Page Load Metrics (883 ± 517 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint703591528943
domContentLoaded11107342311
load5727548831077517
domInteractive11107342311
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 35.01 KiB (1.02%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

matteoscurati
matteoscurati previously approved these changes Apr 15, 2024
Copy link
Contributor

@matteoscurati matteoscurati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Prithpal-Sooriya Prithpal-Sooriya requested a review from danjm April 15, 2024 16:13
… NOTIFY-415-user-storage-user-storage-controller
@metamaskbot
Copy link
Collaborator

Builds ready [509bfd4]
Page Load Metrics (1581 ± 730 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint7184617418589
domContentLoaded126428168
load59386115811520730
domInteractive126428168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 35.01 KiB (1.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@danjm
Copy link
Contributor

danjm commented Apr 17, 2024

@danroc @naugtur I want to confirm that all questions and concerns on the encryption code have been addressed?

@naugtur
Copy link
Contributor

naugtur commented Apr 17, 2024

I brought up one more thing during threat modeling where upon taking a bird's-eye view it doesn't seem to make sense to use profile id in the making of the key for encryption.
Didn't check if it was addressed already.
LMK

@Prithpal-Sooriya
Copy link
Contributor Author

Prithpal-Sooriya commented Apr 17, 2024

@naugtur

I brought up one more thing during threat modeling where upon taking a bird's-eye view it doesn't seem to make sense to use profile id in the making of the key for encryption. Didn't check if it was addressed already. LMK

Yep good comment!
We have a ticket for this here.

Lets sync and discuss this tomorrow - I think there is no hard requirement using the profileId and we can drop it.

Copy link
Contributor

@matteoscurati matteoscurati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Prithpal-Sooriya Prithpal-Sooriya merged commit c370877 into develop Apr 22, 2024
67 of 68 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the NOTIFY-415-user-storage-user-storage-controller branch April 22, 2024 09:50
@github-actions github-actions bot locked and limited conversation to collaborators Apr 22, 2024
@metamaskbot metamaskbot added the release-11.16.0 Issue or pull request that will be included in release 11.16.0 label Apr 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.16.0 Issue or pull request that will be included in release 11.16.0 team-notifications Notifications team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants